import numpy as np
#感知机是线性空间，无法实现异或门
def NAND(x1,x2):
    x=np.array([x1,x2])
    w=np.array([-0.5,-0.5])
    b=0.7
    tmp=np.sum(w*x)+b
    if tmp<=0:
        return 0
    elif tmp>0:
        return 1
def OR(x1,x2):
    x=np.array([x1,x2])
    w=np.array([0.5,0.5])
    b=-0.2
    tmp=np.sum(w*x)+b
    if tmp<=0:
        return 0    
    elif tmp>0:
        return 1
def main():
    print(NAND(0,0))    
    print(NAND(0,1))    
    print(NAND(1,0))    
    print(NAND(1,1))
    
    print(OR(0,0))    
    print(OR(0,1))    
    print(OR(1,0))    
    print(OR(1,1))
if __name__=='__main__':
    main()        